#include <windows.h>
#include <winsock2.h>
#include <tchar.h>
#include "maplay.h"
#include "reader.h"
#include "mahelper.h"

extern int   ID3Encoding;


const int tabbitrate[3][3][16] = 
{
  {{0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},		//V1L1
  {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},		//V1L2
  {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} },	//V1L3

  {{0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},			//V2L1
  {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},				//V2L2
  {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} },			//V2L3

  {{0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},			//V2.5L1
  {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},				//V2.5L2
  {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} }				//V2.5L3
};

const int tabsamplingrate[3][4] = 
{
  {44100, 48000, 32000, 0},
  {22050, 24000, 16000, 0},
  {11025, 12000, 8000, 0}
};

const LPTSTR genre_strings[] = {
  _T("Blues"), _T("Classic Rock"), _T("Country"), _T("Dance"), _T("Disco"),
  _T("Funk"), _T("Grunge"), _T("Hip-Hop"), _T("Jazz"), _T("Metal"),
  _T("New Age"), _T("Oldies"), _T("Other"), _T("Pop"), _T("R&B"),
  _T("Rap"), _T("Reggae"), _T("Rock"), _T("Techno"), _T("Industrial"),
  _T("Alternative"), _T("Ska"), _T("Death Metal"), _T("Pranks"), _T("Soundtrack"),
  _T("Euro-Techno"), _T("Ambient"), _T("Trip-Hop"), _T("Vocal"), _T("Jazz+Funk"),
  _T("Fusion"), _T("Trance"), _T("Classical"), _T("Instrumental"), _T("Acid"),
  _T("House"), _T("Game"), _T("Sound Clip"), _T("Gospel"), _T("Noise"),
  _T("Alternative Rock"), _T("Bass"), _T("Soul"), _T("Punk"), _T("Space"),
  _T("Meditative"), _T("Instrumental Pop"), _T("Instrumental Rock"), _T("Ethnic"), _T("Gothic"),
  _T("Darkwave"), _T("Techno-Industrial"), _T("Electronic"), _T("Pop-Folk"), _T("Eurodance"),
  _T("Dream"), _T("Southern Rock"), _T("Comedy"), _T("Cult"), _T("Gangsta"),
  _T("Top 40"), _T("Christian Rap"), _T("Pop/Funk"), _T("Jungle"), _T("Native American"),
  _T("Cabaret"), _T("New Wave"), _T("Psychadelic"), _T("Rave"), _T("Showtunes"),
  _T("Trailer"), _T("Lo-Fi"), _T("Tribal"), _T("Acid Punk"), _T("Acid Jazz"),
  _T("Polka"), _T("Retro"), _T("Musical"), _T("Rock & Roll"), _T("Hard Rock"),
  _T("Folk"), _T("Folk-Rock"), _T("National Folk"), _T("Swing"), _T("Fast Fusion"),
  _T("Bebob"), _T("Latin"), _T("Revival"), _T("Celtic"), _T("Bluegrass"),
  _T("Avantgarde"), _T("Gothic Rock"), _T("Progressive Rock"), _T("Psychedelic Rock"), _T("Symphonic Rock"),
  _T("Slow Rock"), _T("Big Band"), _T("Chorus"), _T("Easy Listening"), _T("Acoustic"),
  _T("Humour"), _T("Speech"), _T("Chanson"), _T("Opera"), _T("Chamber Music"),
  _T("Sonata"), _T("Symphony"), _T("Booty Bass"), _T("Primus"), _T("Porn Groove"),
  _T("Satire"), _T("Slow Jam"), _T("Club"), _T("Tango"), _T("Samba"),
  _T("Folklore"), _T("Ballad"), _T("Power Ballad"), _T("Rhythmic Soul"), _T("Freestyle"),
  _T("Duet"), _T("Punk Rock"), _T("Drum Solo"), _T("Acapella"), _T("Euro-House"),
  _T("Dance Hall"), _T("Goa"), _T("Drum & Bass"), _T("Club-House"), _T("Hardcore"),
  _T("Terror"), _T("Indie"), _T("BritPop"), _T("Negerpunk"), _T("Polsk Punk"),
  _T("Beat"), _T("Christian Gangsta Rap"), _T("Heavy Metal"), _T("Black Metal"), _T("Crossover"),
  _T("Contemporary Christian"), _T("Christian Rock"), _T("Merengue"), _T("Salsa"), _T("Thrash Metal"),
  _T("Anime"), _T("Jpop"), _T("Synthpop"), NULL
};

BOOL IsValidFile(LPCTSTR pszFile)
{
  BOOL fRet = FALSE;
  CReader* pReader = new CReader();
  if (!pReader->Open(pszFile))
    return FALSE;

  // scan first 4096 bytes
  DWORD dwRead;
  BYTE bBuff[4096];
  if (pReader->Read(bBuff, sizeof(bBuff), &dwRead) && dwRead >= 4) {
    DWORD dwBuff = MAKELONG(MAKEWORD(bBuff[3], bBuff[2]), MAKEWORD(bBuff[1], bBuff[0]));
    if ((dwBuff & 0xFFFFFF00) == 0x49443300)
      fRet = TRUE; // ID3v2 = MP3
    else if (dwBuff == 0x52494646) {
      // RIFF
      if (dwRead >= 12) {
        dwBuff = MAKELONG(MAKEWORD(bBuff[11], bBuff[10]), MAKEWORD(bBuff[9], bBuff[8]));
        if (dwBuff == 0x524D5033) // RMP3
          fRet = TRUE;
        else if (dwBuff == 0x57415645) { // RIFF Wave
          if (dwRead >= 16) {
            dwBuff = MAKELONG(MAKEWORD(bBuff[15], bBuff[14]), MAKEWORD(bBuff[13], bBuff[12]));
            if (dwBuff == 0x666D7420) { // fmt 
              if (dwRead >= 21) {
                dwBuff = MAKELONG(MAKEWORD(bBuff[20], bBuff[21]), 0);
                if (dwBuff == 0x55 ||
                  dwBuff == 0x50) // format id
                  fRet = TRUE;
              }
            }
          }
        }
      }
    }
    else {
      DWORD cb = 0;
      while (cb < dwRead - 4) {
        MPEG_AUDIO_INFO info1, info2;
        if (ParseHeader(bBuff + cb, &info1)) {
          if (cb + info1.nFrameSize + 4 < dwRead) {
            ParseHeader(bBuff + cb + info1.nFrameSize, &info2);
            if (info1.nVersion == info2.nVersion &&
              info1.nLayer == info2.nLayer &&
              info1.nSamplingRate == info2.nSamplingRate) {
                fRet = TRUE;
                break;
            }
          }
        }
        cb++;
      }
    }
  }
  pReader->Close();
  delete pReader;
  return fRet;
}

BOOL ParseHeader(DWORD dwHeader, MPEG_AUDIO_INFO* pinfo)
{
  if (!CheckAudioHeader(dwHeader))
    return FALSE;

  int nPadding;
  MPEG_AUDIO_INFO info;
  info.nVersion = (dwHeader & 0x00100000) ? 2 - ((dwHeader & 0x00080000) >> 19) : 3;
  info.nLayer = 4 - ((dwHeader & 0x00060000) >> 17);
  info.nBitRate = tabbitrate[info.nVersion - 1][info.nLayer - 1][(dwHeader & 0x0000F000) >> 12];
  info.nSamplingRate = tabsamplingrate[info.nVersion - 1][(dwHeader & 0x00000C00) >> 10];
  nPadding = (dwHeader & 0x00000200) >> 9;
  info.nChannels = (((dwHeader & 0x000000C0) >> 6) == 3) ? 1 : 2;
  if (!info.nSamplingRate)
    return FALSE;

  if (!info.nBitRate)
    return FALSE;	// freeformat

  if (info.nLayer == 1) {
    info.nFrameSize = (12 * info.nBitRate * 1000 / info.nSamplingRate + nPadding) * 4;
    info.nSamplesPerFrame = 384;
  }
  else {
    if (info.nLayer >= 2 && info.nVersion >= 2) {
      // LSF
      info.nFrameSize = 72 * info.nBitRate * 1000 / info.nSamplingRate + nPadding;
      info.nSamplesPerFrame = 576;
    }
    else {
      info.nFrameSize = 144 * info.nBitRate * 1000 / info.nSamplingRate + nPadding;
      info.nSamplesPerFrame = 1152;
    }
  }
  *pinfo = info;
  return TRUE;
}

BOOL ParseHeader(LPBYTE pbHeader, MPEG_AUDIO_INFO* pinfo)
{
  DWORD dwHeader = MAKELONG(MAKEWORD(pbHeader[3], pbHeader[2]), 
    MAKEWORD(pbHeader[1], pbHeader[0]));
  return ParseHeader(dwHeader, pinfo);
}

int GetFrameSize(DWORD dwHeader)
{
  if (CheckAudioHeader(dwHeader))
    return 0;

  MPEG_AUDIO_INFO info;
  if (!ParseHeader(dwHeader, &info))
    return 0;

  return info.nFrameSize;
}

int GetFrameSize(LPBYTE pbHeader)
{
  DWORD dwHeader = MAKELONG(MAKEWORD(pbHeader[3], pbHeader[2]), 
    MAKEWORD(pbHeader[1], pbHeader[0]));
  return GetFrameSize(dwHeader);
}

//void ConvertFromTagStr(LPBYTE buff, LPTSTR pszBuff, int size, int cp)
//{
//  int start = 0;
//  int end = 0;
//
//  if ( size <= 0 )
//  {
//    pszBuff[0] = '\0'; return;
//  }
//
//  TCHAR szBuff[MAX_TAG_STR];
//  if ( size > MAX_TAG_STR-1 ) size = MAX_TAG_STR-1;
//
//  memset(szBuff, 0, MAX_TAG_STR);
//  // ID3v2 tags sometimes start with zeroes
//  for (start = 0; start < size && buff[start] == '\0'; start++);
//  if ( start == size ) { pszBuff[0] = '\0'; return; }
//  // ID3v1 tags sometimes have trailing spaces
//  for (end   = size-1; end > start && buff[end] == ' '; end--);
//  // Copy the string value
//  memcpy(szBuff, buff+start, sizeof(BYTE) * (end-start+1));
//  // End the string
//  szBuff[end-start+1] = '\0';
//
//  // Convert to unicode if necessary
//#ifdef _UNICODE
//  if ( cp == -1 ) cp = ID3Encoding;
//  MultiByteToWideChar(cp, 0, (char*)szBuff, -1, pszBuff, MAX_TAG_STR);
//#else
//  strcpy(pszBuff, szBuff);
//#endif
//}
//
//// ID3v2 can contain unicode strings, so a simple wcsncpy is enough.
//// If not, the ConvertFromTagStr function is used to convert to string.
//void ConvertFromID3v2TagStr(LPBYTE buff, LPTSTR pszBuff, int size, BYTE type )
//{
//  if ( type == 1 || type == 2 ) // Unicode
//  {
//    if ( size > MAX_TAG_STR ) size = MAX_TAG_STR;
//    if ( type == 1 && size <= 2 ) // first 2 bytes = encoding
//    {
//      pszBuff[0] = L'\0';
//    }
//    else
//    {
//      memcpy( (void*)pszBuff, buff+((type==1)?2:0), size-((type==1)?2:0) );
//      pszBuff[size/2-1] = '\0';
//    }
//  }
//  else if ( type == 3 ) // UTF-8
//  {
//    ConvertFromTagStr(buff, pszBuff, size, CP_UTF8);
//  }
//  else
//  {
//    ConvertFromTagStr(buff, pszBuff, size, ID3Encoding);
//  }
//}
//
//BOOL GetId3Tag(LPCTSTR pszFile, ID3TAGV1* pTag, void *&cover, UINT *coverSize, int *coverType )
//{
//  memset(pTag, 0, sizeof(ID3TAGV1));
//
//  BOOL fRet = FALSE;
//
//  // Open the file
//  CReader* pReader = new CReader();
//  if (!pReader->Open(pszFile))
//    return FALSE;
//
//  char       id3header[6];
//  DWORD      dwRead;
//  ID3_TAG_V1 id3tag;
//
//  if (pReader->Read((LPBYTE)id3header, 6, &dwRead) && dwRead == 6 // header could be read
//    && strncmp( id3header, "ID3", 3 ) == 0                      // it's an ID3v2 header
//    && id3header[4] <= 4                                        // it's V2.4 or below
//    ) {
//      // ID3 V2
//      //--------
//      fRet = TRUE;
//
//      BYTE version = id3header[3], tags = id3header[5];           // copy version and tags fields to own variables
//
//      LONG size;
//
//      // Tags size
//      pReader->Read((LPBYTE)&size, 4, &dwRead);
//      size = ntohl( size );
//
//      // Extended header
//      if ( (tags&64)==64 )
//      {
//        // get size, then skip it
//        LONG extHdrSize;
//        pReader->Read( (LPBYTE)&extHdrSize, 4, &dwRead );
//        extHdrSize = ntohl( extHdrSize );
//        pReader->SetPointer( extHdrSize, FILE_CURRENT );
//      }
//
//      ULONG  tagSize;
//      ULONG  tagSizeWithHeader;
//      BYTE   tagName[4];
//      BYTE   *tagValue;
//      cover = NULL;
//
//      // As long as the id3 tag size isn't reached
//      for ( ULONG pos = 0; pos < size; pos += tagSizeWithHeader ) {
//        // Up to V2.2, size and tags are stored in 3 bytes, later on in 4 bytes.
//        if( version > 2 ) {
//          pReader->Read( (LPBYTE)tagName, 4, &dwRead );
//          tagSizeWithHeader = 4;
//        }
//        else {
//          pReader->Read( (LPBYTE)tagName, 3, &dwRead );
//          tagSizeWithHeader = 3;
//          tagName[3] = 0;
//        }
//
//        // Empty tag - something's probably wrong, so get out of here...
//        if( !tagName[0] ) {
//          break;
//        }
//
//        // Get tag value size
//        if( version > 2 ) {
//          pReader->Read( (LPBYTE)&tagSize, 4, &dwRead );
//          tagSizeWithHeader += 4;
//        }
//        else {
//          tagSize = 0;
//          pReader->Read( (LPBYTE)(&tagSize)+1, 3, &dwRead );
//          tagSizeWithHeader += 3;
//        }
//        tagSize = ntohl(tagSize);
//        tagSizeWithHeader += tagSize;
//
//        // Skip tag flags
//        if ( version > 2 )
//        {
//          tagSizeWithHeader += 2;
//          pReader->SetPointer( 2, FILE_CURRENT );
//        }
//
//        // Read tag value
//        tagValue = NULL;
//        if(    tagName[0] == 'T'
//          || (strncmp((LPCHAR)tagName,"PIC",3)  == 0)
//          || (strncmp((LPCHAR)tagName,"APIC",4) == 0)
//          || (strncmp((LPCHAR)tagName,"COM",3)  == 0)
//          ) {
//            if ( tagSize <= 409600 )
//            {
//              tagValue = new BYTE[tagSize+1];
//              pReader->Read( (LPBYTE)tagValue, tagSize, &dwRead ); 
//              tagValue[tagSize] = '\0';
//            }
//        }
//
//        // Skip unsupported or too big data
//        if ( tagValue == NULL  )
//        {
//          pReader->SetPointer( tagSize, FILE_CURRENT );
//        }
//        else
//          // Copy the tag values we need into the structure
//        {
//          if ( version > 2 ) {
//            if( strncmp((LPCHAR)tagName, "TIT2", 4) == 0 )
//              ConvertFromID3v2TagStr( tagValue+1, pTag->szTrack, tagSize-1, tagValue[0] );
//            else if( strncmp((LPCHAR)tagName, "TPE1", 4) == 0 )
//              ConvertFromID3v2TagStr( tagValue+1, pTag->szArtist, tagSize-1, tagValue[0] );
//            else if( strncmp((LPCHAR)tagName, "TALB", 4) == 0 )
//              ConvertFromID3v2TagStr( tagValue+1, pTag->szAlbum, tagSize-1, tagValue[0] );
//            else if( strncmp((LPCHAR)tagName, "COMM", 4) == 0 )
//              ConvertFromID3v2TagStr( tagValue+4, pTag->szComment, tagSize-4, tagValue[0] ); // bypass language code
//            else if( strncmp((LPCHAR)tagName, "TYER", 4) == 0
//              && tagSize > 1 ) {
//                TCHAR val[MAX_TAG_STR];
//                ConvertFromID3v2TagStr( tagValue+1, val, tagSize-1, tagValue[0] );
//                pTag->nYear = _ttoi( val );
//                if ( pTag->nYear > 2100 ) // Unix timestamp?
//                {
//                  FILETIME ft;
//                  ft.dwLowDateTime = _wtol(val);
//                  ft.dwHighDateTime = 0;
//                  SYSTEMTIME st;
//                  FileTimeToSystemTime( &ft, &st );
//                  //CTime time( _wtol(val) );
//                  pTag->nYear = st.wYear; //time.GetYear();
//                }
//
//            }
//            else if( strncmp((LPCHAR)tagName, "TRCK", 4) == 0
//              && tagSize > 1 ) {
//                TCHAR val[MAX_TAG_STR];
//                ConvertFromID3v2TagStr( tagValue+1, val, tagSize-1, tagValue[0] );
//                pTag->nTrackNum = _ttoi( val );
//            }
//            else if( strncmp((LPCHAR)tagName, "APIC", 4) == 0
//              && tagSize > 1
//              ) {
//                char imgType[30];
//                strncpy( (LPCHAR)imgType, (LPCHAR)tagValue+1, 29 );
//                BYTE type = tagValue[strlen(imgType)+2];
//                if (   (  type == 3
//                  || (type == 0 && cover == NULL)
//                  )
//                  && (  strcmp((LPCHAR)imgType, "image/png") == 0
//                  || strcmp((LPCHAR)imgType, "image/jpeg") == 0
//                  || strcmp((LPCHAR)imgType, "image/jpg") == 0
//                  || strcmp((LPCHAR)imgType, "image/bmp") == 0
//                  || strcmp((LPCHAR)imgType, "image/gif") == 0
//                  )
//                  )
//                {
//                  int start = strlen(imgType)+3;
//                  if ( tagValue[0] == 1 )
//                  {
//                    while ( *(USHORT*)(tagValue+start) != 0 && start < tagSize ) start+=2;
//                    start+=2;
//                  }
//                  else
//                  {
//                    while ( tagValue[start] != 0 && start < tagSize ) start++;
//                    start++;
//                  }
//
//                  UINT size = tagSize - start;
//                  if ( size != 0 )
//                  {
//                    if ( cover != NULL ) free(cover);
//                    *coverSize = size;
//                    if ( strcmp((LPCHAR)imgType, "image/png") == 0 )
//                      *coverType = 1;
//                    else if ( strcmp((LPCHAR)imgType, "image/bmp") == 0 )
//                      *coverType = 3;
//                    else if ( strcmp((LPCHAR)imgType, "image/gif") == 0 )
//                      *coverType = 4;
//                    else
//                      *coverType = 2;
//
//                    cover = malloc( *coverSize );
//                    if ( cover != NULL )
//                    {
//                      memcpy( cover, (void*)(tagValue+start), *coverSize );
//                    }
//                  }
//                }
//            }
//          }
//          else {
//            if( strncmp((LPCHAR)tagName, "TT2", 3) == 0 )
//              ConvertFromID3v2TagStr( tagValue+1, pTag->szTrack, tagSize-1, tagValue[0] );
//            else if( strncmp((LPCHAR)tagName, "TP1", 3) == 0 )
//              ConvertFromID3v2TagStr( tagValue+1, pTag->szArtist, tagSize-1, tagValue[0] );
//            else if( strncmp((LPCHAR)tagName, "TAL", 3) == 0 )
//              ConvertFromID3v2TagStr( tagValue+1, pTag->szAlbum, tagSize-1, tagValue[0] );
//            else if( strncmp((LPCHAR)tagName, "COM", 3) == 0 )
//              ConvertFromID3v2TagStr( tagValue+5, pTag->szComment+1, tagSize-5, tagValue[0] ); // bypass language code
//            else if( strncmp((LPCHAR)tagName, "TYE", 3) == 0
//              && tagSize > 1 ) {
//                BYTE *val = new BYTE[tagSize+1];
//                strncpy( (LPCHAR)val, (LPCHAR)tagValue+1, tagSize );
//                val[tagSize] = 0;
//                pTag->nYear = atoi( (LPCHAR)tagValue+1 );
//                if ( pTag->nYear > 2100 ) // Unix timestamp?
//                {
//                  FILETIME ft;
//                  ft.dwLowDateTime = atol((LPCHAR)tagValue+1);
//                  ft.dwHighDateTime = 0;
//                  SYSTEMTIME st;
//                  FileTimeToSystemTime( &ft, &st );
//                  pTag->nYear = st.wYear;
//                }
//                delete[] val;
//            }
//            else if( strncmp((LPCHAR)tagName, "TRK", 3) == 0
//              && tagSize > 1 ) {
//                int start;
//                BYTE val[10];
//                for (start = 1; tagValue[start] == '\0' && start < size; start++);
//                strncpy( (LPCHAR)val, (LPCHAR)tagValue+start, tagSize-start );
//                val[dwRead-1] = 0;
//                pTag->nTrackNum = atoi( (LPCHAR)tagValue+1 );
//            }
//            else if( strncmp((LPCHAR)tagName, "PIC", 3) == 0
//              && tagSize > 1 ) {
//                char imgType[4];
//                strncpy( (LPCHAR)imgType, (LPCHAR)tagValue+1, 3 );
//                BYTE type = tagValue[4];
//                if (   type == 3
//                  || (type == 0 && cover == NULL)
//                  && (  _strnicmp((LPCHAR)imgType, "PNG", 3) == 0
//                  || _strnicmp((LPCHAR)imgType, "JPG", 3) == 0
//                  || _strnicmp((LPCHAR)imgType, "BMP", 3) == 0
//                  )
//                  )
//                {
//                  // 0=Encoding, 1-3=PNG/JPG, 4=Img.Type
//                  int start = 5;
//                  if ( tagValue[0] == 1 )
//                  {
//                    while ( *(USHORT*)(tagValue+start) != 0 && start < tagSize ) start+=2;
//                    start+=2;
//                  }
//                  else
//                  {
//                    while ( tagValue[start] != 0 && start < tagSize ) start++;
//                    start++;
//                  }
//
//                  UINT size = tagSize - start;
//                  if ( size != 0 )
//                  {
//                    if ( cover != NULL ) free(cover);
//                    *coverSize = size;
//                    if ( _strnicmp((LPCHAR)imgType, "PNG", 3) == 0 )
//                      *coverType = 1;
//                    else if ( _strnicmp((LPCHAR)imgType, "BMP", 3) == 0 )
//                      *coverType = 3;
//                    else if ( _strnicmp((LPCHAR)imgType, "GIF", 3) == 0 )
//                      *coverType = 4;
//                    else
//                      *coverType = 2;
//
//                    cover = malloc( *coverSize );
//                    if ( cover != NULL )
//                    {
//                      memcpy( cover, (void*)(tagValue+start), *coverSize );
//                    }
//                  }
//                }
//            }
//          }
//        }
//
//        delete[] tagValue;
//      }   // end for tags loop
//  }   // end id3v2
//
//  if ( fRet == FALSE )
//  {
//    // ID3 V1.1
//    LONGLONG llSize = pReader->GetSize();
//    llSize -= sizeof(ID3_TAG_V1);
//    pReader->SetPointer(llSize, FILE_BEGIN);
//
//    if (pReader->Read((LPBYTE)&id3tag, sizeof(id3tag), &dwRead) &&
//      dwRead == sizeof(id3tag)) {
//        if (id3tag.tag[0] == 'T' && id3tag.tag[1] == 'A' && id3tag.tag[2] == 'G') {
//          // it's ID3TAG v1 !!
//          fRet = TRUE;
//
//          if (id3tag.genre < 148)
//            _tcscpy(pTag->szGenre, genre_strings[id3tag.genre]);
//
//          char buff[5];
//          memset(buff, 0, sizeof(buff));
//          memcpy(buff, id3tag.year, sizeof(id3tag.year));
//          buff[4] = '\0';
//          pTag->nYear = atoi(buff);
//
//          ConvertFromTagStr(id3tag.albumName, pTag->szAlbum);
//          ConvertFromTagStr(id3tag.artistName, pTag->szArtist);
//          if ( id3tag.comment[28] == 0 )  // V1.1
//          {
//            ConvertFromTagStr(id3tag.comment, pTag->szComment,28);
//            pTag->nTrackNum = id3tag.track;
//          }
//          else
//          {
//            ConvertFromTagStr(id3tag.comment, pTag->szComment,30);
//            pTag->nTrackNum = 0;
//          }
//          ConvertFromTagStr(id3tag.trackName, pTag->szTrack);
//        }
//    }
//  }
//
//  pReader->Close();
//  delete pReader;
//  return fRet;
//}
//
//BOOL SetId3Tag(LPCTSTR pszFile, ID3TAGV1* pTag)
//{
//  return FALSE;
//}
